//
//  LoginAPIManger.m
//  FindJob
//
//  Created by 233 on 16/3/1.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "LoginAPIManger.h"
#import "NetWorkingConfig.h"
#import "UserModel.h"
#import "ResumeInfoModel.h"

@implementation LoginAPIManger

//- (void)startLoginRequestParameter:(NSDictionary *)parameter success:(void (^)(id))success failure :(void (^)(NSError *))failure{
//    [self startRequestURL:kLoginURL parameters:parameter success:^(id respondsObj) {
//        if (success) {
//            success(respondsObj);
//        }
//    } failure:^(NSError *error) {
//        if (failure) {
//            failure(error);
//        }
//    } timeout:30.0f];
//}
//- (void)startLoginRequestParameter:(NSDictionary *)parameter responds:(void (^)(NetworkingStatus))respondsBlock{
//     [self startRequestURL:kLoginURL parameters:parameter success:^(id respondsObj) {
//         NetworkingStatus status = [self handleResponds:respondsObj];
//         if (respondsBlock) {
//             respondsBlock(status);
//         }
//     } failure:^(NSError *error) {
//         if (error.code == 4) {
//             if (respondsBlock) {
//                 respondsBlock(NetworkingStatusTimeout);
//             }else{
//                 if (respondsBlock) {
//                     respondsBlock(NetworkingStatusError);
//                 }
//             }
//         }
//     } timeout:30.f];
//}
- (void)startLoginRequestParameter:(NSDictionary *)parameter responds:(void (^)(RespondsStatus, NSString *))respondsBlock{
    [self startRequestURL:kLoginURL parameters:parameter success:^(id respondsObj) {
        NSInteger resultCode = [respondsObj[@"resultCode"] integerValue];
        NSString *resultDesc = respondsObj[@"resultDesc"];
        RespondsStatus status;
        if (resultCode == 0) {
            status = RespondsStatusSuccess;
            [UserModel shareUserModel].personID = respondsObj[@"resumePesonalId"];
            [[ResumeInfoModel shareResumeInfoModel] fillWithDictionary:respondsObj[@"resumeShareLists"][0]];
//            NSLog(@"resumeInfo = %@",[ResumeInfoModel shareResumeInfoModel]);
            
        }else{
            status = RespondsStatusDataError;
        }
        if (respondsBlock) {
            respondsBlock(status,resultDesc);
        }
        
    } failure:^(NSError *error) {
        if (respondsBlock) {
            respondsBlock(RespondsStatusNotworkingError,@"网络错误");
        }
        
    } timeout:30.f];
}


#pragma mark *** private ***
//- (NetworkingStatus )handleResponds:(id)responds{
//    NetworkingStatus status;
//    NSInteger resultCode = [responds[@"resultCode"] integerValue];
//    if (resultCode == 0) {
//        status = NetworkingStatusSuccess;
//        [UserModel shareUserModel].personID = responds[@"resumePersonalId"];
//        
//    }else{
//        status = NetworkingStatusError;
//    }
//    return status;
//}
@end
